/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package proxy;

import java.util.Calendar;
import java.util.Date;

/**
 *
 * @author Hue
 */
public class AutoCheck implements Runnable {
    private VPN vpn;

    public AutoCheck(VPN vpn) {
        this.vpn = vpn;
    }

    @Override
    public void run() {
        Calendar cal = Calendar.getInstance();
        while(true) {
            if(vpn.getLastRun() < 0) {
                sleep(10000);
                continue;
            }
            cal.setTime(new Date(vpn.getLastRun()));
            cal.add(Calendar.MINUTE, 5);
            if(cal.getTime().getTime() <= System.currentTimeMillis()) {
                vpn.process();
            }
            sleep(60000);
        }
    }
    
    public void sleep(long millis) {
        try {
            Thread.sleep(millis);
        }
        catch(Exception ex) {
            System.out.println(ex);
        }
    }
}
